package com.xiejr.enumeration;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author mobai
 * @since 2021/2/16 21:01
 */
@Getter
@AllArgsConstructor
public enum OssErrorCode {

    ACCESS_DENIED("AccessDenied", "拒绝访问", "403"),

    BUCKET_ALREADY_EXISTS("BucketAlreadyExists", "存储空间已经存在", "409"),

    BUCKET_NOT_EMPTY("BucketNotEmpty", "存储空间非空", "409"),

    ENTITY_TOO_LARGE("EntityTooLarge", "实体过大", "400"),

    ENTITY_TOO_SMALL("EntityTooSmall", "实体过小", "400"),

    FILE_GROUP_TOO_LARGE("FileGroupTooLarge", "文件组过大", "400"),

    FILE_PART_NOT_EXIST("FilePartNotExist", "文件分片不存在", "400"),

    FILE_PART_STALE("FilePartStale", "文件分片过时", "400"),

    INVALID_ARGUMENT("InvalidArgument", "参数格式错误", "400"),

    INVALID_ACCESS_KEY_ID("InvalidAccessKeyId", "AccessKeyId不存在", "403"),

    INVALID_BUCKET_NAME("InvalidBucketName", "无效的存储空间名称", "400"),

    INVALID_DIGEST("InvalidDigest", "无效的摘要", "400"),

    INVALID_OBJECT_NAME("InvalidObjectName", "无效的文件名称", "400"),

    INVALID_PART("InvalidPart", "无效的分片", "400"),

    INVALID_PART_ORDER("InvalidPartOrder", "无效的分片顺序", "400"),

    INVALID_TARGET_BUCKET_FOR_LOGGING("InvalidTargetBucketForLogging", "Logging操作中有无效的目标存储空间", "400"),

    INTERNAL_ERROR("InternalError", "OSS内部错误", "500"),

    MALFORMED_XML("MalformedXML", "XML格式非法", "400"),

    METHOD_NOT_ALLOWED("MethodNotAllowed", "不支持的方法", "405"),

    MISSING_ARGUMENT("MissingArgument", "缺少参数", "411"),

    MISSING_CONTENT_LENGTH("MissingContentLength", "缺少内容长度", "411"),

    NO_SUCH_BUCKET("NoSuchBucket", "存储空间不存在", "404"),

    NO_SUCH_KEY("NoSuchKey", "文件不存在", "404"),

    NO_SUCH_UPLOAD("NoSuchUpload", "分片上传ID不存在", "404"),

    NOT_IMPLEMENTED("NotImplemented", "无法处理的方法", "501"),

    PRECONDITION_FAILED("PreconditionFailed", "预处理错误", "412"),

    REQUEST_TIME_TOO_SKEWED("RequestTimeTooSkewed", "客户端本地时间和OSS服务器时间相差超过15分钟", "403"),

    REQUEST_TIMEOUT("RequestTimeout", "请求超时", "400"),

    SIGNATURE_DOES_NOT_MATCH("SignatureDoesNotMatch", "签名错误", "403"),

    INVALID_ENCRYPTION_ALGORITHM_ERROR("InvalidEncryptionAlgorithmError", "指定的熵编码加密算法错误", "400");


    private final String code;

    private final String message;

    private final String restStatusCode;

    public static OssErrorCode getInstance(String code){
       return Arrays.asList(OssErrorCode.values()).stream()
                .filter(data->data.getCode().equals(code)).findFirst().orElse(null);


    }
}
